package com.itheima.project_cloth.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.project_cloth.mapper.ClothMapper;
import com.itheima.project_cloth.pojo.Cloth;
import com.itheima.project_cloth.pojo.PageBean;
import com.itheima.project_cloth.service.ClothService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ClothServiceImpl implements ClothService {
    @Autowired
    private ClothMapper clothMapper;

    @Override
    public Cloth selectClothByName(String name) {
        return clothMapper.selectClothByName(name);
    }

    @Override
    public void updateClothById(Cloth cloth) {
        clothMapper.updateClothById(cloth);
    }

    @Override
    public void deleteClothById(List<Integer> ids) {
        clothMapper.deleteClothById(ids);
    }

    @Override
    public void Insert(Cloth cloth) {
        cloth.setCreateTime(LocalDateTime.now());
        cloth.setUpdateTime(LocalDateTime.now());
        clothMapper.insert(cloth);

    }

    @Override
    public PageBean selectClothByKind_Id(Integer page, Integer pageMax, Integer kindId) {
        PageHelper.startPage(page,pageMax);
        List<Cloth> cloths  =  clothMapper.selectClothByKind_Id(kindId);
        Page<Cloth> p = (Page<Cloth>) cloths;
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }
}
